import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/',
  //   name: 'home',
  //   redirect:home,
  //   component: () => import('../views/login.vue')
  // },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/forgetPwd',
    name: 'forgetPwd',
    component: () => import('../views/forgetPwd.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home.vue')  
  },
  {
    path:'/area',
    name:'area',
    component: () => import('../views/area.vue')
  },
  {
    path:'/country',
    name:'country',
    component: () => import('../views/country.vue')
  },
  {
    path:'/personnel',
    name:'personnel',
    component: () => import('../views/personnel.vue')
  },
  {
    path:'/villager',
    name:'villager',
    component: () => import('../views/villager.vue')
  },
  {
    path:'/community',
    name:'community',
    component: () => import('../views/community.vue')
  },
  {
    path:'/house',
    name:'house',
    component: () => import('../views/house.vue')
  },
  {
    path:'/hindex',
    name:'hindex',
    component: () => import('../views/hindex.vue')
  },
  {
    path:'/adviceRank',
    name:'adviceRank',
    component: () => import('../views/adviceRank.vue')
  },
  {
    path:'/checkData',
    name:'checkData',
    component: () => import('../views/checkData.vue')
  },
  {
    path:'/checker',
    name:'checker',
    component: () => import('../views/checker.vue')
  },
  {
    path:'/checkList',
    name:'checkList',
    component: () => import('../views/checkList.vue')
  },
  {
    path:'/adviceTypeList',
    name:'adviceTypeList',
    component: () => import('../views/adviceTypeList.vue')
  },
  {
    path:'/adviceList',
    name:'adviceList',
    component: () => import('../views/adviceList.vue')
  },
  {
    path:'/visitInfoList',
    name:'visitInfoList',
    component: () => import('../views/visitInfoList.vue')
  },
  {
    path:'/visitEventList',
    name:'visitEventList',
    component: () => import('../views/visitEventList.vue')
  },
  {
    path:'/menu',
    name:'menu',
    component: () => import('../views/menu.vue')
  },
  {
    path:'/log',
    name:'log',
    component: () => import('../views/log.vue')
  },
  {
    path:'/newsDetail',
    name:'newsDetail',
    component: () => import('../views/newsDetail.vue')
  },
  {
    path:'/messageList',
    name:'messageList',
    component: () => import('../views/messageList.vue')
  },
  {
    path:'/messageDetail',
    name:'messageDetail',
    component: () => import('../views/messageDetail.vue')
  },
  {
    path:'/authList',
    name:'authList',
    component: () => import('../views/authList.vue')
  },
  {
    path:'/test',
    name:'test',
    component: () => import('../views/test.vue')
  },
  { path: '*', redirect: '/login' },                     //重定向到登陆页面
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  const isLogin = localStorage.tsToken ? true : false;
  if(to.path == '/login' || to.path == '/forgetPwd'){
    next();
  }
  else{
    if (isLogin) {
      next();
    }
    else{
      next('/login');
    }
  }
})

export default router
